package com.ikangtai.shecare.stickycalendar.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.ImageView;

import com.ikangtai.shecare.R;
import com.ikangtai.shecare.common.util.AppLog;
import com.ikangtai.shecare.stickycalendar.http.SymptomHttp;
import com.ikangtai.shecare.stickycalendar.http.util.SymptomMsg;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by wangling on 16/9/8.
 */
public class PhyListAdapter extends BaseAdapter {
    private ViewHolder viewHolder;
    private Context mContext;
    private List<String> mListBeen;

    private int symptomHeadache; //头疼
    private int symptomVertigo; //眩晕
    private int symptomAcne; //粉刺
    private int symptomVomit; //呕吐

    private int symptomGreedyColdDrink; //贪冷饮
    private int symptomGreedySpicy; //嗜辛辣
    private int symptomPoorAppetite; //食欲不佳

    private int symptomAbdominalDistention; //小腹坠胀
    private int symptomDiarrhea; //腹泻
    private int symptomConstipation; //便秘

    private int symptomFever; //发热
    private int symptomWholeBodyAches; //全身酸痛

    private int symptomDreaminess; //多梦
    private int symptomFret; //烦躁
    private int symptomInsomnia; //失眠

    private int symptomStayUpLate; //熬夜
    private int symptomDrinkWine; //饮酒
    private int symptomLongJourney; //长途旅行

    private int symptomInfo;
    private List<SymptomMsg> symptomMsgList;

    public PhyListAdapter(Context mContext, List<String> mListBeen) {
        this.mContext = mContext;
        this.mListBeen = mListBeen;
    }


    @Override
    public int getCount() {
        return mListBeen.size();
    }

    @Override
    public Object getItem(int position) {
        return mListBeen.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }


    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        viewHolder = new ViewHolder();
        LayoutInflater inflater = LayoutInflater.from(mContext);
        if (convertView == null) {
            convertView = inflater.inflate(R.layout
                    .dialog_phy_detail, null);

            viewHolder.phy_item1 = (CheckBox) convertView.findViewById(R.id.phy_item1);
            viewHolder.phy_item2 = (CheckBox) convertView.findViewById(R.id.phy_item2);
            viewHolder.phy_item3 = (CheckBox) convertView.findViewById(R.id.phy_item3);
            viewHolder.phy_item4 = (CheckBox) convertView.findViewById(R.id.phy_item4);
            viewHolder.phy_item5 = (CheckBox) convertView.findViewById(R.id.phy_item5);
            viewHolder.phy_item6 = (CheckBox) convertView.findViewById(R.id.phy_item6);
            viewHolder.phy_item7 = (CheckBox) convertView.findViewById(R.id.phy_item7);
            viewHolder.phy_item8 = (CheckBox) convertView.findViewById(R.id.phy_item8);
            viewHolder.phy_item9 = (CheckBox) convertView.findViewById(R.id.phy_item9);
            viewHolder.phy_item10 = (CheckBox) convertView.findViewById(R.id.phy_item10);
            viewHolder.phy_item11 = (CheckBox) convertView.findViewById(R.id.phy_item11);
            viewHolder.phy_item12 = (CheckBox) convertView.findViewById(R.id.phy_item12);
            viewHolder.phy_item13 = (CheckBox) convertView.findViewById(R.id.phy_item13);
            viewHolder.phy_item14 = (CheckBox) convertView.findViewById(R.id.phy_item14);
            viewHolder.phy_item15 = (CheckBox) convertView.findViewById(R.id.phy_item15);
            viewHolder.phy_item16 = (CheckBox) convertView.findViewById(R.id.phy_item16);
            viewHolder.phy_item17 = (CheckBox) convertView.findViewById(R.id.phy_item17);
            viewHolder.phy_item18 = (CheckBox) convertView.findViewById(R.id.phy_item18);

            viewHolder.save = (ImageView) convertView.findViewById(R.id.header_view_save);

            viewHolder.phy_item1.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
                @Override
                public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                    AppLog.i("wzz---phy_item1---" + isChecked);
                    if (isChecked) {
                        viewHolder.phy_item1.setTextColor(mContext.getResources().getColor(R.color.white));
                        symptomHeadache = 1;
                    } else {
                        viewHolder.phy_item1.setTextColor(mContext.getResources().getColor(R.color.black));

                    }
                }
            });

            viewHolder.phy_item2.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
                @Override
                public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                    AppLog.i("wzz---phy_item2---" + isChecked);
                    if (isChecked) {
                        viewHolder.phy_item2.setTextColor(mContext.getResources().getColor(R.color.white));

                        symptomVertigo = 1;
                    } else {
                        viewHolder.phy_item2.setTextColor(mContext.getResources().getColor(R.color.black));

                    }

                }
            });
            viewHolder.phy_item3.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
                @Override
                public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                    if (isChecked) {
                        viewHolder.phy_item3.setTextColor(mContext.getResources().getColor(R.color.white));

                        symptomAcne = 1;
                    } else {
                        viewHolder.phy_item3.setTextColor(mContext.getResources().getColor(R.color.black));

                    }
                }
            });
            viewHolder.phy_item4.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
                @Override
                public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                    if (isChecked) {
                        viewHolder.phy_item4.setTextColor(mContext.getResources().getColor(R.color.white));

                        symptomVomit = 1;
                    } else {
                        viewHolder.phy_item4.setTextColor(mContext.getResources().getColor(R.color.black));

                    }
                }
            });
            viewHolder.phy_item5.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
                @Override
                public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                    if (isChecked) {
                        viewHolder.phy_item5.setTextColor(mContext.getResources().getColor(R.color.white));

                        symptomGreedyColdDrink = 1;
                    } else {
                        viewHolder.phy_item5.setTextColor(mContext.getResources().getColor(R.color.black));

                    }
                }
            });
            viewHolder.phy_item6.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
                @Override
                public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                    if (isChecked) {
                        viewHolder.phy_item6.setTextColor(mContext.getResources().getColor(R.color.white));

                        symptomGreedySpicy = 1;
                    } else {
                        viewHolder.phy_item6.setTextColor(mContext.getResources().getColor(R.color.black));

                    }
                }
            });
            viewHolder.phy_item7.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
                @Override
                public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                    if (isChecked) {
                        viewHolder.phy_item7.setTextColor(mContext.getResources().getColor(R.color.white));

                        symptomPoorAppetite = 1;
                    } else {
                        viewHolder.phy_item7.setTextColor(mContext.getResources().getColor(R.color.black));

                    }
                }
            });
            viewHolder.phy_item8.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
                @Override
                public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                    if (isChecked) {
                        viewHolder.phy_item8.setTextColor(mContext.getResources().getColor(R.color.white));

                        symptomAbdominalDistention = 1;
                    } else {
                        viewHolder.phy_item8.setTextColor(mContext.getResources().getColor(R.color.black));

                    }
                }
            });
            viewHolder.phy_item9.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
                @Override
                public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                    if (isChecked) {
                        viewHolder.phy_item9.setTextColor(mContext.getResources().getColor(R.color.white));

                        symptomDiarrhea = 1;
                    } else {
                        viewHolder.phy_item9.setTextColor(mContext.getResources().getColor(R.color.black));

                    }
                }
            });


            viewHolder.phy_item10.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
                @Override
                public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                    if (isChecked) {
                        viewHolder.phy_item10.setTextColor(mContext.getResources().getColor(R.color.white));

                        symptomConstipation = 1;
                    } else {
                        viewHolder.phy_item10.setTextColor(mContext.getResources().getColor(R.color.black));

                    }
                }
            });

            viewHolder.phy_item11.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
                @Override
                public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                    if (isChecked) {
                        viewHolder.phy_item11.setTextColor(mContext.getResources().getColor(R.color.white));

                        symptomFever = 1;
                    } else {
                        viewHolder.phy_item11.setTextColor(mContext.getResources().getColor(R.color.black));

                    }
                }
            });

            viewHolder.phy_item12.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
                @Override
                public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                    if (isChecked) {
                        viewHolder.phy_item12.setTextColor(mContext.getResources().getColor(R.color.white));

                        symptomWholeBodyAches = 1;
                    } else {
                        viewHolder.phy_item12.setTextColor(mContext.getResources().getColor(R.color.black));

                    }
                }
            });

            viewHolder.phy_item13.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
                @Override
                public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                    if (isChecked) {
                        viewHolder.phy_item13.setTextColor(mContext.getResources().getColor(R.color.white));

                        symptomDreaminess = 1;
                    } else {
                        viewHolder.phy_item13.setTextColor(mContext.getResources().getColor(R.color.black));

                    }
                }
            });
            viewHolder.phy_item14.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
                @Override
                public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                    if (isChecked) {
                        viewHolder.phy_item14.setTextColor(mContext.getResources().getColor(R.color.white));

                        symptomFret = 1;
                    } else {
                        viewHolder.phy_item14.setTextColor(mContext.getResources().getColor(R.color.black));

                    }
                }
            });

            viewHolder.phy_item15.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
                @Override
                public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                    if (isChecked) {
                        viewHolder.phy_item15.setTextColor(mContext.getResources().getColor(R.color.white));

                        symptomInsomnia = 1;
                    } else {
                        viewHolder.phy_item15.setTextColor(mContext.getResources().getColor(R.color.black));

                    }
                }
            });

            viewHolder.phy_item16.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
                @Override
                public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                    if (isChecked) {
                        viewHolder.phy_item16.setTextColor(mContext.getResources().getColor(R.color.white));

                        symptomStayUpLate = 1;
                    } else {
                        viewHolder.phy_item16.setTextColor(mContext.getResources().getColor(R.color.black));

                    }
                }
            });

            viewHolder.phy_item17.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
                @Override
                public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                    if (isChecked) {
                        viewHolder.phy_item17.setTextColor(mContext.getResources().getColor(R.color.white));

                        symptomDrinkWine = 1;
                    } else {
                        viewHolder.phy_item17.setTextColor(mContext.getResources().getColor(R.color.black));

                    }
                }
            });

            viewHolder.phy_item18.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
                @Override
                public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                    if (isChecked) {
                        viewHolder.phy_item18.setTextColor(mContext.getResources().getColor(R.color.white));

                        symptomLongJourney = 1;
                    } else {
                        viewHolder.phy_item18.setTextColor(mContext.getResources().getColor(R.color.black));

                    }
                }
            });

            viewHolder.save.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {

                    symptomInfo = (symptomHeadache << 13) | (symptomVertigo << 9) | (symptomAcne << 23) | (symptomVomit << 24) | (symptomGreedyColdDrink << 25) |
                            (symptomGreedySpicy << 26) | (symptomPoorAppetite << 27) | (symptomAbdominalDistention << 28) | (symptomDiarrhea << 29) |
                            (symptomConstipation << 30) | (symptomFever << 7) | (symptomWholeBodyAches << 16) | (symptomDreaminess << 31) | (symptomFret << 11) | (symptomInsomnia << 0) | (symptomStayUpLate << 5) |
                            (symptomDrinkWine << 3) | (symptomLongJourney << 4);

                    AppLog.i("wzz----symptomInfo----" + symptomInfo);

                    symptomMsgList = new ArrayList<SymptomMsg>();
                    SymptomMsg symptomMsg = new SymptomMsg();
                    symptomMsg.setDateRecord("2016-09-11");
                    symptomMsg.setSymptomInfo(symptomInfo);
                    symptomMsgList.add(symptomMsg);
                    SymptomHttp SymptomHttp = new SymptomHttp(mContext, symptomMsgList);
                    SymptomHttp.saveSelectedDayRecord();

                }
            });

            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }


        return convertView;
    }


    static class ViewHolder {

        private CheckBox phy_item1, phy_item2, phy_item3, phy_item4, phy_item5, phy_item6,
                phy_item7, phy_item8, phy_item9, phy_item10, phy_item11, phy_item12,
                phy_item13, phy_item14, phy_item15, phy_item16, phy_item17, phy_item18;
        private ImageView save;
    }


}
